/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Window.java
 *
 * Created on 2011-3-14, 21:28:30
 */
package fir;

import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author zhangyucen
 */
public class Window extends javax.swing.JFrame {

    boolean gameStarted = false;
    boolean PcPlay = false;
    boolean NetPlay = false;
    boolean NetOK = false;
    boolean player1 = false;
    boolean player2 = false;
    boolean wait = false;
    String serverip;
    int serverport;
    String clientip;
    int clientport;
    String remoteip;
    ServerSocket serversocket;
    Socket conn;
    ServerThread serverthread;
    int mode = 0; // 0=normal, 1=client, 2=server;
    int disconnecting = 0;
    SocketThread socketthread;
    InputStream in;
    OutputStream out;
    Message message;
    ServerDialog serverdialog;
    ClientDialog clientdialog;
    ChessBoard board;
    ChessLine judge;
    Computer computer;

    public void beginning() {
        gameStarted = false;
        jMenuItem3.setEnabled(false);
        jMenuItem7.setEnabled(false);
        jMenu5.setEnabled(true);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        if (languageChoose == Language.CHINESE) {
            jLabel1.setText("黑棋[玩家]等待中");
            jLabel2.setText("白棋[电脑]等待中");
            jLabel6.setText("游戏尚未开始");
        } else {
            jLabel1.setText("Black[Player] waiting");
            jLabel2.setText("White[Computer] waiting");
            jLabel6.setText("Game has not started");
        }
    }

    private void refresh() {    //refresh the JFrame when the game starts or restarts
        gameStarted = true;
        PcPlay = true;
        player1 = true;
        player2 = false;

        conn = null;
        NetOK = false;
        serversocket = null;
        in = null;
        out = null;
        NetPlay = false;
        mode = 0;

        jMenuItem7.setEnabled(true);
        jMenuItem3.setEnabled(true);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton2.setEnabled(true);
        jMenu5.setEnabled(false);
        if (languageChoose == Language.CHINESE) {
            jLabel1.setText("->黑棋[玩家]行动");
            jLabel6.setText("游戏进行中");
        } else {
            jLabel1.setText("->Black[Player] take action");
            jLabel6.setText("Game in progress");
        }
        board.chess.init();
        /*
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                board.chess.point[i][j] = 0;
            }
        }*/
        board.draw();
        textPrint(board.chess.current);
    }

    enum Language {

        CHINESE, ENGLISH
    };
    Language languageChoose = Language.CHINESE;

    enum AILevel {

        EASY, MIDDLE, HARD
    }
    AILevel AILevelChoose = AILevel.EASY;

    enum Turn {

        BLACK, WHITE;
    }
    Turn turnChoose = Turn.BLACK;

    /** Creates new form Window */
    public Window() {
        initComponents();
        judge = new ChessLine(board.chess);
        computer = new Computer(judge);
        message = new Message(this);
        serverdialog = new ServerDialog(this);
        clientdialog = new ClientDialog(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        AILevelGroup = new javax.swing.ButtonGroup();
        languageGroup = new javax.swing.ButtonGroup();
        LoadDialog = new javax.swing.JFileChooser();
        SaveDialog = new javax.swing.JFileChooser();
        AboutGame = new javax.swing.JDialog();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        Help = new javax.swing.JDialog();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        boardChoose = new javax.swing.JDialog();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        boardChooseGroup = new javax.swing.ButtonGroup();
        chessChoose = new javax.swing.JDialog();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        chessChooseGroup = new javax.swing.ButtonGroup();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jPanel7 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel3 = board = new ChessBoard();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu7 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItem2 = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItem3 = new javax.swing.JRadioButtonMenuItem();
        jMenu6 = new javax.swing.JMenu();
        jRadioButtonMenuItem4 = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItem5 = new javax.swing.JRadioButtonMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        jCheckBoxMenuItem2 = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();

        LoadDialog.setCurrentDirectory(new java.io.File("D:\\学习资料\\学习\\程序设计\\NetBeans\\FIR\\src\\Save"));
        LoadDialog.setDialogTitle("载入棋局");

        SaveDialog.setCurrentDirectory(new java.io.File("D:\\学习资料\\学习\\程序设计\\NetBeans\\FIR\\src\\Save"));
        SaveDialog.setDialogTitle("保存棋局");

        AboutGame.setTitle("关于游戏");
        AboutGame.setAlwaysOnTop(true);
        AboutGame.setResizable(false);

        jLabel9.setFont(new java.awt.Font("华文彩云", 1, 24));
        jLabel9.setText("小Q五子棋");

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/about.jpg"))); // NOI18N

        jLabel12.setText("版权所有 ⓒ 2011 Software College。保留所有权利");

        javax.swing.GroupLayout AboutGameLayout = new javax.swing.GroupLayout(AboutGame.getContentPane());
        AboutGame.getContentPane().setLayout(AboutGameLayout);
        AboutGameLayout.setHorizontalGroup(
            AboutGameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AboutGameLayout.createSequentialGroup()
                .addGap(105, 105, 105)
                .addComponent(jLabel9))
            .addGroup(AboutGameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AboutGameLayout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addContainerGap())
        );
        AboutGameLayout.setVerticalGroup(
            AboutGameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AboutGameLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Help.setTitle("帮助文档");
        Help.setAlwaysOnTop(true);

        jTextArea1.setColumns(20);
        jTextArea1.setFont(new java.awt.Font("宋体", 0, 13));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("【帮助文档】\n一、规则\n1.五子棋是两个人之间进行的竞技活动，由于对黑方白方规则不同，黑棋必须先行。\n2.五子棋专用盘为 15×15 ，五连子的方向为横、竖、斜。\n3.禁手是对局中被判为负的行棋手段。白棋无禁手。\n4.在棋盘上以对局双方均不可能形成五连为和棋。\n5.在对局中，以在盘上落下的子又拿起来为拔子，判负。在对局中，一方自行终止比赛，判负。\n6.黑方在落下关键的第五子即形成五连的同时，又形成禁手。此时因黑方已成连五，故禁手失效，黑方胜。\n7.所谓黑方形成禁手，是指黑方一子落下同时形成两个或两个以上的活三、冲四及长连禁手。此时，白方应立即向黑方指出禁手，自然而胜。\n\n二、相关名词\n四：指活四和冲四。\n活四：己方再加上一子，有两个点可以成五的单四。\n冲四：己方再加上一子，只有一个点可以成五的四。包括连冲四和跳冲四，跳冲四又称“嵌五”\n三：指活三和眠三。\n活三：己方再加上一子，可以形成活四的三。\n眠三：己方再加上一子，可以形成冲四但不能形成活四的三。\n四三胜：指同时具备两个先手，其中一个是四，另一个是活三的取胜方法。这是黑棋的主要取胜战术。\n禁手：对局中禁止使用而被判负的行棋手段。连珠中只有黑棋有禁手，有三三禁手、四四禁手、长连禁手等。\n三三禁手：黑方一子落下，同时形成两个或两个以上的活三。\n四四禁手：黑方一子落下，同时形成两个或两个以上的四。\n长连禁手：黑方一子落下，形成一个或一个以上的长连。\n先五为胜：黑棋五连与禁手同时形成，禁手失效，黑方胜。\n");
        jTextArea1.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextArea1.setEnabled(false);
        jScrollPane1.setViewportView(jTextArea1);

        jButton1.setText("关闭");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout HelpLayout = new javax.swing.GroupLayout(Help.getContentPane());
        Help.getContentPane().setLayout(HelpLayout);
        HelpLayout.setHorizontalGroup(
            HelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HelpLayout.createSequentialGroup()
                .addGroup(HelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(HelpLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE))
                    .addGroup(HelpLayout.createSequentialGroup()
                        .addGap(107, 107, 107)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        HelpLayout.setVerticalGroup(
            HelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, HelpLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap())
        );

        boardChoose.setTitle("棋盘选择");
        boardChoose.setAlwaysOnTop(true);
        boardChoose.setResizable(false);

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/wood/board.jpg"))); // NOI18N

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test1/board.jpg"))); // NOI18N

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test2/board.jpg"))); // NOI18N

        boardChooseGroup.add(jRadioButton1);

        boardChooseGroup.add(jRadioButton2);

        boardChooseGroup.add(jRadioButton3);

        jButton5.setText("确定");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("取消");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout boardChooseLayout = new javax.swing.GroupLayout(boardChoose.getContentPane());
        boardChoose.getContentPane().setLayout(boardChooseLayout);
        boardChooseLayout.setHorizontalGroup(
            boardChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(boardChooseLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(10, Short.MAX_VALUE))
            .addGroup(boardChooseLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(jRadioButton1)
                .addGap(86, 86, 86)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
                .addComponent(jRadioButton3)
                .addGap(42, 42, 42))
            .addGroup(boardChooseLayout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(jButton5)
                .addGap(26, 26, 26)
                .addComponent(jButton6)
                .addContainerGap(95, Short.MAX_VALUE))
        );
        boardChooseLayout.setVerticalGroup(
            boardChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(boardChooseLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(boardChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(boardChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton1)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton3))
                .addGap(18, 18, 18)
                .addGroup(boardChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        chessChoose.setTitle("棋子选择");
        chessChoose.setAlwaysOnTop(true);
        chessChoose.setResizable(false);

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/wood/black.png"))); // NOI18N

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/wood/white.png"))); // NOI18N

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test1/black.png"))); // NOI18N

        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test1/white.png"))); // NOI18N

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test2/black.png"))); // NOI18N

        jLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/test2/white.png"))); // NOI18N

        chessChooseGroup.add(jRadioButton4);

        chessChooseGroup.add(jRadioButton5);

        chessChooseGroup.add(jRadioButton6);

        jButton7.setText("确定");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("取消");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout chessChooseLayout = new javax.swing.GroupLayout(chessChoose.getContentPane());
        chessChoose.getContentPane().setLayout(chessChooseLayout);
        chessChooseLayout.setHorizontalGroup(
            chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chessChooseLayout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(chessChooseLayout.createSequentialGroup()
                        .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel18)
                            .addComponent(jLabel20))
                        .addGap(30, 30, 30)
                        .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel19)
                            .addComponent(jLabel21))
                        .addGap(23, 23, 23)
                        .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jRadioButton4)
                            .addComponent(jRadioButton5)
                            .addComponent(jRadioButton6)))
                    .addGroup(chessChooseLayout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)))
                .addGap(21, 21, 21))
        );
        chessChooseLayout.setVerticalGroup(
            chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chessChooseLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(chessChooseLayout.createSequentialGroup()
                        .addComponent(jRadioButton4)
                        .addGap(27, 27, 27)
                        .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton5)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18)))
                    .addComponent(jLabel17)
                    .addComponent(jLabel16))
                .addGap(18, 18, 18)
                .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel21)
                    .addComponent(jLabel20)
                    .addComponent(jRadioButton6))
                .addGap(43, 43, 43)
                .addGroup(chessChooseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jButton8))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("五子棋");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new java.awt.BorderLayout(5, 5));

        jPanel4.setPreferredSize(new java.awt.Dimension(637, 60));
        jPanel4.setLayout(new java.awt.GridLayout(2, 3, 5, 5));

        jLabel1.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel1.setText("黑棋[玩家]等待中");
        jLabel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel1);

        jLabel2.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel2.setText("白棋[电脑]等待中");
        jLabel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel2);

        jLabel3.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel3.setText("人机对战模式（简单）");
        jLabel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel3);

        jLabel4.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel4.setText("黑棋：0");
        jLabel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel4);

        jLabel5.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel5.setText("白棋：0");
        jLabel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel5);

        jLabel6.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel6.setText("游戏尚未开始");
        jLabel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.add(jLabel6);

        getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.BorderLayout(5, 5));

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jPanel2.setPreferredSize(new java.awt.Dimension(152, 473));
        jPanel2.setLayout(new java.awt.GridLayout(2, 1, 0, 5));

        jLabel7.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("时间");

        jLabel8.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel8.setText("黑棋");

        jTextField1.setEditable(false);
        jTextField1.setFont(new java.awt.Font("宋体", 1, 12));
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField1.setText("00：00：00.000");

        jLabel10.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel10.setText("白棋");

        jTextField3.setEditable(false);
        jTextField3.setFont(new java.awt.Font("宋体", 1, 12));
        jTextField3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField3.setText("00：00：00.000");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel8))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addGap(18, 18, 18)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.add(jPanel5);

        jPanel6.setLayout(new java.awt.BorderLayout());

        jTextArea2.setColumns(20);
        jTextArea2.setFont(new java.awt.Font("宋体", 0, 13));
        jTextArea2.setRows(5);
        jTextArea2.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextArea2.setEnabled(false);
        jScrollPane2.setViewportView(jTextArea2);

        jPanel6.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jPanel7.setPreferredSize(new java.awt.Dimension(150, 70));

        jButton2.setText("悔棋");
        jButton2.setEnabled(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("上步");
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("下步");
        jButton4.setEnabled(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jButton2))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.add(jPanel7, java.awt.BorderLayout.PAGE_END);

        jPanel2.add(jPanel6);

        jPanel1.add(jPanel2, java.awt.BorderLayout.LINE_END);

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jPanel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jPanel3MousePressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel1.add(jPanel3, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jMenuBar1.setFont(new java.awt.Font("微软雅黑", 0, 14));
        jMenuBar1.setMinimumSize(new java.awt.Dimension(58, 25));
        jMenuBar1.setPreferredSize(new java.awt.Dimension(58, 25));

        jMenu1.setMnemonic('G');
        jMenu1.setText("游戏（G）");
        jMenu1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jMenu1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("开始游戏");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenu7.setMnemonic('J');
        jMenu7.setText("局域网游戏（J）");
        jMenu7.setEnabled(false);

        jMenuItem10.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem10.setText("创建游戏");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu7.add(jMenuItem10);

        jMenuItem11.setText("加入游戏");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem11ActionPerformed(evt);
            }
        });
        jMenu7.add(jMenuItem11);

        jMenuItem12.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem12.setText("断开连接");
        jMenuItem12.setEnabled(false);
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem12ActionPerformed(evt);
            }
        });
        jMenu7.add(jMenuItem12);

        jMenuItem13.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem13.setText("重置");
        jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem13ActionPerformed(evt);
            }
        });
        jMenu7.add(jMenuItem13);

        jMenu1.add(jMenu7);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("载入棋局");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("保存棋局");
        jMenuItem3.setEnabled(false);
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem7.setText("终止棋局");
        jMenuItem7.setEnabled(false);
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem7);
        jMenu1.add(jSeparator1);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed1(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu2.setMnemonic('S');
        jMenu2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jMenu2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jMenu5.setMnemonic('D');
        jMenu5.setText("难度（D）");

        jRadioButtonMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        AILevelGroup.add(jRadioButtonMenuItem1);
        jRadioButtonMenuItem1.setSelected(true);
        jRadioButtonMenuItem1.setText("简单");
        jRadioButtonMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem1ActionPerformed(evt);
            }
        });
        jMenu5.add(jRadioButtonMenuItem1);

        jRadioButtonMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        AILevelGroup.add(jRadioButtonMenuItem2);
        jRadioButtonMenuItem2.setText("中等");
        jRadioButtonMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem2ActionPerformed(evt);
            }
        });
        jMenu5.add(jRadioButtonMenuItem2);

        jRadioButtonMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        AILevelGroup.add(jRadioButtonMenuItem3);
        jRadioButtonMenuItem3.setText("困难");
        jRadioButtonMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem3ActionPerformed(evt);
            }
        });
        jMenu5.add(jRadioButtonMenuItem3);

        jMenu2.add(jMenu5);

        jMenu6.setMnemonic('L');
        jMenu6.setText("语言（L）");

        jRadioButtonMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        languageGroup.add(jRadioButtonMenuItem4);
        jRadioButtonMenuItem4.setSelected(true);
        jRadioButtonMenuItem4.setText("简体中文");
        jRadioButtonMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem4ActionPerformed(evt);
            }
        });
        jMenu6.add(jRadioButtonMenuItem4);

        jRadioButtonMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        languageGroup.add(jRadioButtonMenuItem5);
        jRadioButtonMenuItem5.setText("英语");
        jRadioButtonMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItem5ActionPerformed(evt);
            }
        });
        jMenu6.add(jRadioButtonMenuItem5);

        jMenu2.add(jMenu6);
        jMenu2.add(jSeparator2);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("棋盘");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("棋子");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);
        jMenu2.add(jSeparator3);

        jCheckBoxMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jCheckBoxMenuItem2.setText("开启音效");
        jMenu2.add(jCheckBoxMenuItem2);

        jCheckBoxMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jCheckBoxMenuItem1.setText("开启音乐");
        jCheckBoxMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jCheckBoxMenuItem1);

        jMenuItem14.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem14.setText("切换音乐");
        jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem14ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem14);

        jMenuBar1.add(jMenu2);

        jMenu3.setMnemonic('A');
        jMenu3.setText("关于（A）");
        jMenu3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jMenu3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem8.setText("关于游戏");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem8);

        jMenuBar1.add(jMenu3);

        jMenu4.setMnemonic('H');
        jMenu4.setText("帮助（H）");
        jMenu4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jMenu4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jMenuItem9.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jMenuItem9.setText("帮助文档");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem9);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-653)/2, (screenSize.height-601)/2, 653, 601);
    }// </editor-fold>//GEN-END:initComponents

    private void jPanel3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel3MousePressed
        // TODO add your handling code here:
        int x, y;
        int i, j;
        x = evt.getX();
        y = evt.getY();
        j = (x - board.lineBeginX + board.lineWidth / 2) / board.lineWidth;
        i = (y - board.lineBeginY + board.lineWidth / 2) / board.lineWidth;
        /*if (gameStarted && i < 15 && j < 15 && board.chess.point[i][j] == 0) {
        board.chess.modify(i, j, 1);
        board.draw();
        }*/
        if (gameStarted && i < 15 && j < 15 && !full() && board.chess.point[i][j] == 0) {
            chesslistener(i, j);
        }
    }//GEN-LAST:event_jPanel3MousePressed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        if (gameStarted) //game has started
        {
            String detail, title;
            if (languageChoose == Language.ENGLISH) {
                detail = "Are you sure you want to restart the current game ?";
                title = "Tips";
            } else {
                detail = "你确定要重新开始当前正在进行的游戏吗？";
                title = "提示";
            }
            int choose = javax.swing.JOptionPane.showConfirmDialog(
                    this, detail, title, javax.swing.JOptionPane.YES_NO_OPTION);
            if (choose == 0) {
                refresh();
                if (jCheckBoxMenuItem2.isSelected())
                    Sound.newgame();
            } else {
                return;
            }
        } else {
            refresh();
            if (jCheckBoxMenuItem2.isSelected())
                Sound.newgame();
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        if (gameStarted) //game has started
        {
            String detail, title;
            if (languageChoose == Language.ENGLISH) {
                detail = "Are you sure you want to exit the current game ?";
                title = "Tips";
            } else {
                detail = "你确定要退出当前正在进行的游戏吗？";
                title = "提示";
            }
            int choose = javax.swing.JOptionPane.showConfirmDialog(
                    this, detail, title, javax.swing.JOptionPane.YES_NO_OPTION);
            if (choose == 0) {
                System.exit(0);
            } else {
                return;
            }
        } else {
            System.exit(0);
        }
    }//GEN-LAST:event_formWindowClosing

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        // TODO add your handling code here:
        if (gameStarted) //game has started
        {
            String detail, title;
            if (languageChoose == Language.ENGLISH) {
                detail = "Are you sure you want to exit the current game ?";
                title = "Tips";
            } else {
                detail = "你确定要退出当前正在进行的游戏吗？";
                title = "提示";
            }
            int choose = javax.swing.JOptionPane.showConfirmDialog(
                    this, detail, title, javax.swing.JOptionPane.YES_NO_OPTION);
            if (choose == 0) {
                System.exit(0);
            } else {
                return;
            }
        } else {
            System.exit(0);
        }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // TODO add your handling code here:
        String detail, title;
        if (languageChoose == Language.ENGLISH) {
            detail = "Are you sure you want to end up the current game ?";
            title = "Tips";
        } else {
            detail = "你确定要终止当前正在进行的游戏吗？";
            title = "提示";
        }
        int choose = javax.swing.JOptionPane.showConfirmDialog(
                this, detail, title, javax.swing.JOptionPane.YES_NO_OPTION);
        if (choose == 0) {
            gameStarted = false;
            jButton3.setEnabled(true);
            jButton4.setEnabled(true);
            jMenu5.setEnabled(true);
            jMenuItem3.setEnabled(false);
            jMenuItem7.setEnabled(false);
            if (languageChoose == Language.CHINESE) {
                jLabel1.setText("黑棋[玩家]等待中");
                jLabel6.setText("游戏尚未开始");
            } else {
                jLabel1.setText("Black[Player] waiting");
                jLabel6.setText("Game has not started");
            }
        } else {
            return;
        }
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jRadioButtonMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem1ActionPerformed
        // TODO add your handling code here:
        AILevelChoose = AILevel.EASY;
        if (languageChoose == Language.CHINESE) {
            jLabel3.setText("人机对战模式（简单）");
        } else {
            jLabel3.setText("Player vs Computer(Easy)");
        }
    }//GEN-LAST:event_jRadioButtonMenuItem1ActionPerformed

    private void jRadioButtonMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem2ActionPerformed
        // TODO add your handling code here:
        AILevelChoose = AILevel.MIDDLE;
        if (languageChoose == Language.CHINESE) {
            jLabel3.setText("人机对战模式（中等）");
        } else {
            jLabel3.setText("Player vs Computer(Middle)");
        }
    }//GEN-LAST:event_jRadioButtonMenuItem2ActionPerformed

    private void jRadioButtonMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem3ActionPerformed
        // TODO add your handling code here:
        AILevelChoose = AILevel.HARD;
        if (languageChoose == Language.CHINESE) {
            jLabel3.setText("人机对战模式（困难）");
        } else {
            jLabel3.setText("Player vs Computer(Hard)");
        }
    }//GEN-LAST:event_jRadioButtonMenuItem3ActionPerformed

    private void jRadioButtonMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem4ActionPerformed
        // TODO add your handling code here:
        if (languageChoose == Language.ENGLISH) {
            languageChoose = Language.CHINESE;
            jMenu1.setText("游戏（G）");
            jMenu2.setText("设置（S）");
            jMenu3.setText("关于（A）");
            jMenuItem8.setText("关于游戏");
            AboutGame.setTitle("关于游戏");
            jMenu4.setText("帮助（H）");
            jMenuItem9.setText("查看帮助");
            Help.setTitle("帮助文档");
            jButton1.setText("关闭");
            boardChoose.setTitle("棋盘选择");
            jButton5.setText("确定");
            jButton6.setText("取消");
            chessChoose.setTitle("棋子选择");
            jButton7.setText("确定");
            jButton8.setText("取消");

            jMenuItem1.setText("单人游戏");
            jMenu7.setText("局域网游戏（J）");
            jMenuItem10.setText("创建游戏");
            jMenuItem11.setText("加入游戏");
            jMenuItem12.setText("断开连接");
            jMenuItem13.setText("重置");
            jMenuItem2.setText("载入棋局");
            jMenuItem3.setText("保存棋局");
            jMenuItem7.setText("终止棋局");
            jMenuItem4.setText("退出");

            jMenu5.setText("难度（D）");
            jMenu6.setText("语言（L）");
            jMenuItem5.setText("棋盘");
            jMenuItem6.setText("棋子");
            jRadioButtonMenuItem1.setText("简单");
            jRadioButtonMenuItem2.setText("中等");
            jRadioButtonMenuItem3.setText("困难");
            jRadioButtonMenuItem4.setText("简体中文");
            jRadioButtonMenuItem5.setText("英语");
            jCheckBoxMenuItem1.setText("开启音乐");
            jMenuItem14.setText("切换音乐");

            jLabel7.setText("时间");
            jLabel8.setText("黑棋");
            jLabel10.setText("白棋");

            jButton2.setText("悔棋");
            jButton3.setText("上步");
            jButton4.setText("下步");

            if (gameStarted) {
                if (turnChoose == Turn.BLACK) {
                    jLabel1.setText("->黑棋[玩家]行动");
                    jLabel2.setText("白棋[电脑]等待中");
                } else {
                    jLabel1.setText("黑棋[玩家]等待中");
                    jLabel2.setText("->白棋[电脑]行动");
                }
                jLabel6.setText("游戏进行中");
            } else {
                jLabel1.setText("黑棋[玩家]等待中");
                jLabel2.setText("白棋[电脑]等待中");
                jLabel6.setText("游戏尚未开始");
            }

            String aiLevel = "";
            if (AILevelChoose == AILevel.EASY) {
                aiLevel = "简单";
            } else if (AILevelChoose == AILevel.MIDDLE) {
                aiLevel = "中等";
            } else {
                aiLevel = "困难";
            }
            jLabel3.setText("人机对战模式（" + aiLevel + ")");

            //for the moment
            jLabel4.setText("黑棋：0");
            jLabel5.setText("白棋：0");

            textPrint(board.chess.current);
        } else {
            return;
        }
    }//GEN-LAST:event_jRadioButtonMenuItem4ActionPerformed

    private void jRadioButtonMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItem5ActionPerformed
        // TODO add your handling code here:
        if (languageChoose == Language.CHINESE) {
            languageChoose = Language.ENGLISH;
            jMenu1.setText("Game（G）");
            jMenu2.setText("Set（S）");
            jMenu3.setText("About（A）");
            jMenuItem8.setText("About Game");
            AboutGame.setTitle("About Game");
            jMenu4.setText("Help（H）");
            jMenuItem9.setText("View Help");
            Help.setTitle("Help Doucumentation");
            jButton1.setText("Close");
            boardChoose.setTitle("Board Selection");
            jButton5.setText("OK");
            jButton6.setText("Cancel");
            chessChoose.setTitle("Chess Selection");
            jButton7.setText("OK");
            jButton8.setText("Cancle");

            jMenuItem1.setText("Single Game");
            jMenu7.setText("LAN Game（J）");
            jMenuItem10.setText("Server");
            jMenuItem11.setText("Client");
            jMenuItem12.setText("Disconnect");
            jMenuItem13.setText("Reset");
            jMenuItem2.setText("Load Game");
            jMenuItem3.setText("Save Game");
            jMenuItem7.setText("End Game");
            jMenuItem4.setText("Exit");

            jMenu5.setText("Difficulty（D）");
            jMenu6.setText("Language（L）");
            jMenuItem5.setText("Chessboard");
            jMenuItem6.setText("Chess");
            jRadioButtonMenuItem1.setText("Easy");
            jRadioButtonMenuItem2.setText("Middle");
            jRadioButtonMenuItem3.setText("Hard");
            jRadioButtonMenuItem4.setText("Chinese");
            jRadioButtonMenuItem5.setText("English");
            jCheckBoxMenuItem1.setText("Music");
            jMenuItem14.setText("Next Music");

            jLabel7.setText("Time");
            jLabel8.setText("Black");
            jLabel10.setText("White");

            jButton2.setText("Undo");
            jButton3.setText("Back");
            jButton4.setText("Next");

            if (gameStarted) {
                if (turnChoose == Turn.BLACK) {
                    jLabel1.setText("->Black[Player] take action");
                    jLabel2.setText("White[Computer] waiting");
                } else {
                    jLabel1.setText("Black[Player] waiting");
                    jLabel2.setText("->White[Computer] take action");
                }
                jLabel6.setText("Game in progress");
            } else {
                jLabel1.setText("Black[Player] waiting");
                jLabel2.setText("White[Computer] waiting");
                jLabel6.setText("Game has not started");
            }

            String aiLevel = "";
            if (AILevelChoose == AILevel.EASY) {
                aiLevel = "Easy";
            } else if (AILevelChoose == AILevel.MIDDLE) {
                aiLevel = "Middle";
            } else {
                aiLevel = "Hard";
            }
            jLabel3.setText("Player vs. Computer（" + aiLevel + ")");

            //for the moment
            jLabel4.setText("Black：0");
            jLabel5.setText("White：0");

            textPrint(board.chess.current);
        } else {
            return;
        }
    }//GEN-LAST:event_jRadioButtonMenuItem5ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        if (gameStarted) {
            String detail, title;
            if (languageChoose == Language.ENGLISH) {
                detail = "Are you sure you want to end up the current game to load game?";
                title = "Tips";
            } else {
                detail = "你确定要终止当前正在进行的游戏而载入游戏吗？";
                title = "提示";
            }
            int choose = javax.swing.JOptionPane.showConfirmDialog(
                    this, detail, title, javax.swing.JOptionPane.YES_NO_OPTION);
            if (choose == 1) //cancel
            {
                return;
            }
        }
        int returnVal = LoadDialog.showOpenDialog(this);
        if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
            //judge if player be sure to exit current game
            File file = LoadDialog.getSelectedFile();
            try {
                FileInputStream fistream = new FileInputStream(file);
                InputStreamReader filein = new InputStreamReader(fistream);
                board.chess.init();
                if (filein.read() == 0)
                    gameStarted = false;
                else
                    gameStarted = true;
                boolean b_w, x_y = true;
                int c;
                while ((c = filein.read()) != -1) {
                    if (x_y) {
                        board.chess.xAccess[board.chess.current] = c;
                        x_y = !x_y;
                    } else {
                        board.chess.yAccess[board.chess.current] = c;
                        x_y = !x_y;
                        board.chess.current++;
                    }
                }
                filein.close();
                if (gameStarted) {
                    jMenuItem7.setEnabled(true);
                    jMenuItem3.setEnabled(true);
                    jButton3.setEnabled(false);
                    jButton4.setEnabled(false);
                    jButton2.setEnabled(true);
                    jMenu5.setEnabled(false);
                    if (languageChoose == Language.CHINESE) {
                        jLabel1.setText("->黑棋[玩家]行动");
                        jLabel6.setText("游戏进行中");
                    } else {
                        jLabel1.setText("->Black[Player] take action");
                        jLabel6.setText("Game in progress");
                    }
                    b_w = true;
                    for (int i = 0; i < board.chess.current; i++) {
                        board.chess.point[board.chess.xAccess[i]][board.chess.yAccess[i]] = (b_w?1:2);
                        b_w = !b_w;
                    }
                    board.draw();
                    textPrint(board.chess.current);
                } else {
                    beginning();
                    if (languageChoose == Language.ENGLISH) {
                        jLabel6.setText("Loading Game");
                    } else {
                        jLabel6.setText("载入游戏");
                    }
                    board.chess.pos = 0;
                    //jButton3.setEnabled(true);
                    jButton4.setEnabled(true);
                    textPrint(board.chess.pos);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } else {
            return;
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        int returnVal = SaveDialog.showSaveDialog(this);
        if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
            //the next operation is empty for the moment
            File file = SaveDialog.getSelectedFile();
            try {
                FileOutputStream fostream = new FileOutputStream(file);
                OutputStreamWriter fileout = new OutputStreamWriter(fostream);
                if (gameStarted)
                    fileout.write(1);
                else
                    fileout.write(0);
                for (int i = 0; i < board.chess.current; i++) {
                    fileout.write(board.chess.xAccess[i]);
                    fileout.write(board.chess.yAccess[i]);
                }
                fileout.close();
            } catch (IOException ex) {
                Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            return;
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // TODO add your handling code here:
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        AboutGame.setBounds((screenSize.width - (331 + 16)) / 2, (screenSize.height - (310 + 38)) / 2, 331 + 16, 310 + 38);
        AboutGame.setVisible(true);
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Help.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        // TODO add your handling code here:
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        Help.setBounds((screenSize.width - (271 + 16)) / 2, (screenSize.height - (330 + 38)) / 2, 271 + 16, 330 + 38);
        Help.setVisible(true);
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        String choose = "";
        if (jRadioButton1.isSelected()) {
            choose = "wood";
        }
        if (jRadioButton2.isSelected()) {
            choose = "test1";
        }
        if (jRadioButton3.isSelected()) {
            choose = "test2";
        }
        board.boardpic = java.awt.Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/" + choose + "/board.jpg"));
        boardChoose.setVisible(false);
        board.draw();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        boardChoose.setVisible(false);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // TODO add your handling code here:
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        boardChoose.setBounds((screenSize.width - (323 + 16)) / 2, (screenSize.height - (217 + 38)) / 2, 323 + 16, 217 + 38);
        boardChoose.setVisible(true);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        // TODO add your handling code here:
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        chessChoose.setBounds((screenSize.width - (169 + 16)) / 2, (screenSize.height - (225 + 38)) / 2, 169 + 16, 225 + 38);
        chessChoose.setVisible(true);
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        String choose = "";
        if (jRadioButton4.isSelected()) {
            choose = "wood";
        }
        if (jRadioButton5.isSelected()) {
            choose = "test1";
        }
        if (jRadioButton6.isSelected()) {
            choose = "test2";
        }
        board.whitepoint = java.awt.Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/" + choose + "/white.png"));
        board.blackpoint = java.awt.Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/" + choose + "/black.png"));
        chessChoose.setVisible(false);
        board.draw();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        chessChoose.setVisible(false);
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        board.chess.regret();
        board.draw();
        if (jCheckBoxMenuItem2.isSelected())
            Sound.takeback();
        textPrint(board.chess.current);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        if (board.chess.pos >= 0 && board.chess.pos < board.chess.current) {
            board.chess.point[board.chess.xAccess[board.chess.pos]][board.chess.yAccess[board.chess.pos]] = (board.chess.pos%2 == 0?1:2);
            board.chess.pos++;
        }
        if (board.chess.pos > 0)
            jButton3.setEnabled(true);
        if (board.chess.pos >= board.chess.current)
            jButton4.setEnabled(false);
        board.draw();
        if (jCheckBoxMenuItem2.isSelected())
            Sound.falldown();
        textPrint(board.chess.pos);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if (board.chess.pos > 0 && board.chess.pos <= board.chess.current) {
            board.chess.point[board.chess.xAccess[board.chess.pos-1]][board.chess.yAccess[board.chess.pos-1]] = 0;
            board.chess.pos--;
        }
        if (board.chess.pos <= 0)
            jButton3.setEnabled(false);
        if (board.chess.pos < board.chess.current)
            jButton4.setEnabled(true);
        board.draw();
        if (jCheckBoxMenuItem2.isSelected())
            Sound.falldown();
        textPrint(board.chess.pos);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed
        // TODO add your handling code here:
        if (jCheckBoxMenuItem1.isSelected())
            BGM.playMusic();
        else
            BGM.stopMusic();
    }//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed

    private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem14ActionPerformed
        // TODO add your handling code here:
        if (jCheckBoxMenuItem1.isSelected())
            BGM.changeNext();
    }//GEN-LAST:event_jMenuItem14ActionPerformed

    private void jMenuItem13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem13ActionPerformed
        // TODO add your handling code here:
        reset();
        if (NetPlay && NetOK) {
            message.command = 1;
            message.send();
            //提示信息（暂缺）
        }
}//GEN-LAST:event_jMenuItem13ActionPerformed

    private void jMenuItem12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem12ActionPerformed
        // TODO add your handling code here:
        if (out != null) {
            message.command = 10;
            message.send();
        }
        disconnect();
        //提示信息（暂缺）
}//GEN-LAST:event_jMenuItem12ActionPerformed

    private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
        // TODO add your handling code here:
        clientdialog.setLocation(150, 150);
        clientdialog.setVisible(true);
        PcPlay = false;
        NetPlay = true;
        player1 = false;
        player2 = true;
        reset();
        try {
            disconnect();
            conn = new Socket(serverip, serverport);
            in = conn.getInputStream();
            out = conn.getOutputStream();
            wait = true;
            NetPlay = true;
            player1 = false;
            player2 = true;
            setThread();
            mode = 1;
            //提示信息（暂缺）
        } catch (IOException ex) {
            reset();
            NetOK = false;
            JOptionPane.showMessageDialog(null, "Connect error!", "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jMenuItem11ActionPerformed

    private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
        // TODO add your handling code here:
        serverdialog.setLocation(150, 150); //改进
        serverdialog.setVisible(true);
        PcPlay = false;
        NetPlay = true;
        player1 = true;
        player2 = false;
        reset();
        startserver();
        mode = 2;
        //设置提示（暂缺）
}//GEN-LAST:event_jMenuItem10ActionPerformed

    private void jMenuItem4ActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed1
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem4ActionPerformed1

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Window().setVisible(true);
            }
        });
    }

    public void reset() {
        if (board.chess != null) {
            board.chess.init();
        }
        board.draw();
        textPrint(board.chess.current);
    }

    public boolean full() {
        boolean full = false;
        int count = 0;
        if (board.chess != null) {
            for (int i = 0; i < 15; i++) {
                for (int j = 0; j < 15; j++) {
                    if (board.chess.point[i][j] == 0) {
                        full = false;
                        break;
                    }
                    count++;
                }
            }
        }
        if (count == 225) {
            full = true;
        }

        return full;
    }

    void chesslistener(int i, int j) {
        if (PcPlay) {
            if (player1) {
                board.chess.modify(i, j, 1);
                player1 = false;
                player2 = true;
                board.draw();
                if (jCheckBoxMenuItem2.isSelected())
                    Sound.falldown();
                textPrint(board.chess.current);
                whowin();
            }
            if (player2 && board.chess != null && gameStarted) {
                computer.location();
                i = computer.row;
                j = computer.line;
                board.chess.modify(i, j, 2);
                player1 = true;
                player2 = false;
                board.draw();
                if (jCheckBoxMenuItem2.isSelected())
                    Sound.falldown();
                textPrint(board.chess.current);
                whowin();
            }
        }
        if (NetPlay) {
            if (wait == false) {
                wait = true;
                message.row = i;
                message.col = j;
                message.command = 2;
                message.send();
                if (player1) {
                    board.chess.modify(i, j, 1);
                }
                if (player2) {
                    board.chess.modify(i, j, 2);
                }
                board.draw();
                if (jCheckBoxMenuItem2.isSelected())
                    Sound.falldown();
                textPrint(board.chess.current);
                this.setTitle("五子棋（Waiting for competitor）");
                whowin();
            }
        }
    }

    public void textPrint(int currentPos) {
        String str = "";
        String color;
        if (languageChoose == Language.ENGLISH) {
            for (int i = 0; i < currentPos; i++) {
                color = (i%2 == 0)?"Black":"White";
                str += color + " [ " + (board.chess.xAccess[i]+1) + "," + (board.chess.yAccess[i]+1) + " ] \n";
            }
        } else {
            for (int i = 0; i < currentPos; i++) {
                color = (i%2 == 0)?"黑棋":"白棋";
                str += color + " [ " + (board.chess.xAccess[i]+1) + "," + (board.chess.yAccess[i]+1) + " ] \n";
            }
        }
        jTextArea2.setText(str);
    }

    public void whowin() {
        judge.Count();
        String detail, title;
        if (judge.judge() == 0) {
            if (languageChoose == Language.ENGLISH) {
                detail = "Black Win !";
                title = "Result";
            } else {
                detail = "黑棋获胜！";
                title = "结果";
            }
            if (jCheckBoxMenuItem2.isSelected())
                Sound.win();
            javax.swing.JOptionPane.showMessageDialog(
                    this, detail, title, javax.swing.JOptionPane.INFORMATION_MESSAGE);
            beginning();
            jMenuItem3.setEnabled(true);
            if (languageChoose == Language.ENGLISH) {
                jLabel6.setText("Game ended");
            } else {
                jLabel6.setText("游戏结束");
            }
        } else if (judge.judge() == 1) {
            if (languageChoose == Language.ENGLISH) {
                detail = "White Win !";
                title = "Result";
            } else {
                detail = "白棋获胜！";
                title = "结果";
            }
            if (jCheckBoxMenuItem2.isSelected())
                Sound.lose();
            javax.swing.JOptionPane.showMessageDialog(
                    this, detail, title, javax.swing.JOptionPane.INFORMATION_MESSAGE);
            beginning();
            jMenuItem3.setEnabled(true);
            if (languageChoose == Language.ENGLISH) {
                jLabel6.setText("Game ended");
            } else {
                jLabel6.setText("游戏结束");
            }
        }
    }

    public void startserver() {
        if (serverthread != null) {
            disconnect();
        }
        serverthread = new ServerThread(this);
        serverthread.start();
    }

    public void setThread() {
        NetOK = true;
        /*disconnectMenuItem.setEnabled(true);
        PlayToPcMenuItem.setEnabled(false);
        iAmServerMenuItem.setEnabled(false);
        iAmClientMenuItem.setEnabled(false);*/
        jMenuItem12.setEnabled(true);
        jMenuItem1.setEnabled(false);
        jMenuItem10.setEnabled(false);
        jMenuItem11.setEnabled(false);
        socketthread = new SocketThread(this);
        socketthread.start();
        remoteip = conn.getRemoteSocketAddress().toString();
        JOptionPane.showMessageDialog(null, "Connect to " + remoteip
                + " successfully", "Information",
                JOptionPane.INFORMATION_MESSAGE);
        if (player1) {
            this.setTitle("五子棋（Your turn...）");
        }
        if (player2) {
            this.setTitle("五子棋（Waiting for competitor...）");
        }
    }

    void disconnect() {
        if (conn == null) {
            return;
        }
        disconnecting = 1;
        socketthread.StopRun();
        socketthread = null;
        serverthread = null;
        if (mode == 1) {
            try {
                in.close();
                out.close();
                conn.close();
            } catch (IOException e) {
            }
        }
        if (mode == 2) {
            try {
                in.close();
                out.close();
                conn.close();
                serversocket.close();
            } catch (IOException e) {
            }
        }
        in = null;
        out = null;
        conn = null;
        serversocket = null;
        NetOK = false;
        NetPlay = false;
        PcPlay = false;
        //frame.setTitle("FiveChess RICM-MCA2005");
        /*disconnectMenuItem.setEnabled(false);
        PlayToPcMenuItem.setEnabled(true);
        iAmServerMenuItem.setEnabled(true);
        iAmClientMenuItem.setEnabled(true);*/
        this.setTitle("五子棋");
        jMenuItem12.setEnabled(false);
        jMenuItem1.setEnabled(true);
        jMenuItem10.setEnabled(true);
        jMenuItem11.setEnabled(true);
        reset();
        mode = 0;
        disconnecting = 0;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup AILevelGroup;
    private javax.swing.JDialog AboutGame;
    private javax.swing.JDialog Help;
    private javax.swing.JFileChooser LoadDialog;
    private javax.swing.JFileChooser SaveDialog;
    private javax.swing.JDialog boardChoose;
    private javax.swing.ButtonGroup boardChooseGroup;
    private javax.swing.JDialog chessChoose;
    private javax.swing.ButtonGroup chessChooseGroup;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu7;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem2;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem3;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem4;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.ButtonGroup languageGroup;
    // End of variables declaration//GEN-END:variables
}
